Repository navigation
Conversation
Listens to ElementCachesInvalidated, skips drafts and revisions, and queues a tag purge on the default client if it can purge by tag. Every client's queue is flushed after the request or command, and after each queued job; failed purges are reported instead of thrown. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1fc17-c592-763a-a600-e76afae5cd1f
In FOSHttpCache, purging means URL purges (PurgeCapable). The listener calls invalidateTags() on TagCapable clients, and core's event is ElementCachesInvalidated.
Core renamed ResponseTagger to ResponseCacheInfo and moved it to CraftCms\Cms\Http. Amp-Thread-ID: https://ampcode.com/threads/T-01a1fc17-c592-763a-a600-e76afae5cd1f Co-authored-by: Amp <amp@ampcode.com>
Contributor
Author
|
Landed directly on main (807f69e), with InvalidateElementTags and core's ResponseCacheInfo. While the package is new, we're committing to main instead of opening PRs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Purges a site's cached pages when Craft invalidates element caches.
ElementCachesInvalidated, queues a tag purge on the default client with the same element tags core collects from queries, such aselement::5andelement::CraftCms\Cms\Entry\Elements\Entry::*. Drafts and revisions are skipped, and so are clients that can't purge by tag.HttpCache::flush()sends every client's queued purges once, after the request or console command and after each queued job. A failed purge is reported rather than thrown, so a CDN outage doesn't fail the save.Asset, transform, folder and URI purges come next. They'll listen to core's change events once that PR lands.
What this package is
FOSHttpCache is a framework-agnostic library for talking to caching proxies:
CacheInvalidatorFOSHttpCacheBundle wires the library into Symfony: configuration, the invalidator as a service, tag headers on responses, and invalidation rules.
This package plays the same role for Craft and Laravel. Drivers below lists its parts.
The bundle can't be used here because it needs Symfony's FrameworkBundle. This package doesn't yet have the bundle's path-based cache-control rules or user-context hashing.
Drivers
Core fills
ResponseCacheInfowith the response's tags and expiry. A driver uses the package for the rest:HttpCachefacade (HttpCacheManager): named FOSHttpCache clients fromconfig/http-cache.php.HttpCache::invalidator()purges by tag or URL;HttpCache::extend()adds drivers.CachePolicy(defaultDefaultCachePolicy): whether a request may be served from a cache and whether a response may be stored. Drivers checkisResponseCacheable()before adding their own header, such asCDN-Cache-Control.SendTagHeader: writesResponseCacheInfo::getTags()to the configured tag header, such asCache-Tagorxkey.InvalidateElementTags: turn core's change events ([6.x] Add change events for caches and CDNs cms#21048) intoHttpCache::invalidator()calls.Related issues